package com.focus.ctrl.demo.web.maphandler;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class CookieValueController {

	@RequestMapping("cookie/add")
	@ResponseBody
	public String addCookie(HttpServletResponse response) {
		Cookie cookie = new Cookie("loginCount", "1");
		response.addCookie(cookie);
		return "1234";
	}

	@RequestMapping("cookie/edit")
	@ResponseBody
	public String editCookie(@CookieValue("loginCount") String loginCount,
			HttpServletResponse response) {
		int i = Integer.parseInt(loginCount);
		i++;
		Cookie cookie = new Cookie("loginCount", i + "");
		response.addCookie(cookie);
		return "5678";
	}
}
